// ----------------------------------------------------
//		Loader Functions
// ----------------------------------------------------
function loadTabMenu()
{
//	$(document).ready(function(){
		$('#menu a').click(function() //start function when any link is clicked from #menu
		{ 
			$(".spacingcontent").slideUp("slow");
				var content_show = $(this).attr("title"); //retrieve title of link so we can compare with php file
				$.ajax({
					method: "get",url: $(this).attr("title") + ".php",
					data: "page"+content_show,
					beforeSend: function()
					{
						//$("#loading").show("slow");
						}, //show loading just when link is clicked
					complete: function()
					{
						//$("#loading").hide("slow");
						}, //stop showing loading when the process is complete
					success: function(html)
					{ //so, if data is retrieved, store it in html
						$(".spacingcontent").show("slow"); //animation
						$(".spacingcontent").html(html); //show the html inside .content div
					}
				});
			});
//	});
}
function loadinfo(page, options)
{

	$.ajax({
		type: "get",
		url: page,
		data: options,
		beforeSend: function()  //show loading just when link is clicked
		{
			$(".spacingcontent").hide("slow");
			//$("#loading").show("slow");
		},
		complete: function()  //stop showing loading
		{
			//$("#loading").hide("slow");
		},
		success: function(html){
			$(".spacingcontent").show("slow");
			$(".spacingcontent").html(html);
		}
	});
}
function loadAdmininfo(page, options)
{
	$.ajax({
		type: "get",
		url: page,
		data: options,
		beforeSend: function()  //show loading just when link is clicked
		{
			$("#acontent").hide("slow");
			$("#loading").show("slow");
		},
		complete: function()  //stop showing loading
		{
			$("#loading").hide("slow");
		},
		success: function(html){
			$("#acontent").show("slow");
			$("#acontent").html(html);
		}
	});
}
function loadsorter() {
	// call the tablesorter plugin
	$("table")
	.tablesorter({
		sortForce: [[0,0]], 
		widthFixed: true
	})
	.tablesorterPager({
		container: $("#pager"), 
		positionFixed: false
	}); 
}

function loadsorterAttend() {
	// call the tablesorter plugin
	$("table")
	.tablesorter({
		sortForce: [[3,0]], 
		widthFixed: true
	})
	.tablesorterPager({
		container: $("#pager"),
		positionFixed: false
	});
}

function loadsorterEvent() {
	// call the tablesorter plugin
	$("table")
	.tablesorter({
		sortForce: [[2,0]],
		widthFixed: true
	})
	.tablesorterPager({
		container: $("#pager"),
		positionFixed: false
	});
}

// This loads the accordion
function loadAccordion()
{
	$("#accordion").accordion({
		header: "h4", 
		collapsible: true, 
		autoHeight: false
	})
}

// Loads the inpage pop up
function loadPopupCalls()
{
	var popupStatus = 0; 
	//LOADING POPUP
	//Click the button event!
	$(".button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

}
// ---------------------------------------------
//		Helper Functions
// ---------------------------------------------
function newlinefix(input)
{
	// This function can be used with an onChange
	//		to put proper newlines into textareas
	outputtxt=input.replace(String.fromCharCode(10),"<br>");
	return outputtxt;
}
// This function is for submitting checkboxes
// frm is the name of the form
function checkboxSubmit(frm)
{
	var num = -1;
	var output = "";
	$('input:checkbox:checked').each(function(index)
	{
		//alert(index + ': ' + $(this).val());
		num++;
		var tmp = output + "&chck" + num + "=" + $(this).val();
		output = tmp;
	});
	num++;
	var tmp = output + "&numchk=" + num;
	output = tmp;
	return output;
}
// -----------------------------------------------
// 	Popup Functions
// -----------------------------------------------
//SETTING UP OUR POPUP  
//0 means disabled; 1 means enabled;  
var popupStatus = 0;  

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0)
	{
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1)
	{
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}
function placePhoto(who, type)
{
	var file;
	var html;
	if(type == 'a')
	{
		file = "aimg.php";
	}
	else
	{
		file = "cimg.php";
	}
	html = "<center><img src='" + file + "?id=" + who + "'></center>"
	$('#contactArea').html(html);
}
function placeTitle(title)
{
	$('#popupTitle').html(title);
}
